home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / text / misc / MSWordView_src.lha / mswordview / annotations.c next >
C/C++ Source or Header  |  1998-12-15  |  5KB  |  171 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include "config.h"
  6. #include "mswordview.h"
  7.  
  8. extern FILE *erroroutput;
  9. extern FILE *outputfile;
  10. extern long int cp;
  11. extern int insuper;
  12.  
  13. ATRD *key_atrd;
  14.  
  15. void decode_annotation(textportions *portions, FILE *main)
  16.     {
  17.     int i,j;
  18.     /*
  19.     search in the first thing for the cp of this
  20.     reference.
  21.     */
  22.     i=0;
  23.     while(i<portions->andref_no)
  24.         {
  25.         if (portions->andRef[i] == cp)
  26.             {
  27.             error(erroroutput,"found correct anno ref pos at %x, index was %d\n",portions->andRef[i],i);
  28.             if (!insuper)
  29.                 fprintf(outputfile,"<sup>");
  30.             fprintf(outputfile,"<a href=\"#");
  31.             j = portions->the_atrd[i].xstUsrInitl[0];
  32.             for (j=1;j<portions->the_atrd[i].xstUsrInitl[0]+1;j++)
  33.                     {
  34.                     /*warning despite the possibility of being 16 bit nos ive done this*/
  35.                     fprintf(outputfile,"%c",portions->the_atrd[i].xstUsrInitl[j]);
  36.                     }
  37.             fprintf(outputfile,"%d\">",i);
  38.             j = portions->the_atrd[i].xstUsrInitl[0];
  39.             key_atrd[portions->the_atrd[i].ibst].xstUsrInitl[0] = j;
  40.             key_atrd[portions->the_atrd[i].ibst].ibst = portions->the_atrd[i].ibst;
  41.             for (j=1;j<portions->the_atrd[i].xstUsrInitl[0]+1;j++)
  42.                     {
  43.                     /*warning despite the possibility of being 16 bit nos ive done this*/
  44.                     fprintf(outputfile,"%c",portions->the_atrd[i].xstUsrInitl[j]);
  45.                     key_atrd[portions->the_atrd[i].ibst].xstUsrInitl[j] = portions->the_atrd[i].xstUsrInitl[j];
  46.                     }
  47.             fprintf(outputfile,"%d</a>",i+1);
  48.  
  49.             if (!insuper)
  50.                 fprintf(outputfile,"</sup>");
  51.             break;
  52.             }
  53.         i++;
  54.         }
  55.  
  56.     /*part deux*/
  57.     /*
  58.     now to hold off to the very end any spray them all out, or at the end of every page.
  59.     ill do the latter for the moment
  60.     */
  61.     if ( (i < portions->andref_no ) && (i < 256) )
  62.         portions->list_annotations[portions->list_anno_no++] = i;
  63.     else if (i >= 256)
  64.         fprintf(erroroutput,"oops silly programmer :-) lost an annotation\n");
  65.     }
  66.  
  67.  
  68. stringgroup *extract_authors(FILE *tablefd,U32 fcGrpXstAtnOwners,U32 lcbGrpXstAtnOwners)
  69.     {
  70.     U16 len,i;
  71.     U32 count=0;
  72.     stringgroup *authorlist=NULL;
  73.     stringgroup *current=NULL;
  74.  
  75.     if (lcbGrpXstAtnOwners > 0)
  76.         {
  77.         fseek(tablefd,fcGrpXstAtnOwners,SEEK_SET);
  78.         authorlist = (stringgroup*) malloc(sizeof(stringgroup));
  79.  
  80.         if (authorlist == NULL)
  81.             {
  82.             fprintf(erroroutput,"not enough mem for annotation group\n");
  83.             return(NULL);
  84.             }
  85.  
  86.         authorlist->next = NULL;
  87.         authorlist->author = NULL;
  88.         authorlist->noofstrings=0;
  89.         current = authorlist;
  90.  
  91.         while (count < lcbGrpXstAtnOwners)
  92.             {
  93.             len = read_16ubit(tablefd);
  94.             count+=2;
  95.             current->author = malloc((len+1) * sizeof(U16));
  96.             authorlist->noofstrings++;
  97.             if (current->author == NULL)
  98.                 {
  99.                 fprintf(erroroutput,"not enough mem for author string of len %d\n",len);
  100.                 break;
  101.                 }
  102.             for (i=0;i<len;i++)
  103.                 {
  104.                 current->author[i] = read_16ubit(tablefd);
  105.                 count+=2;
  106.                 }
  107.             current->author[i] = '\0';
  108.  
  109.             if (count < lcbGrpXstAtnOwners)
  110.                 {
  111.                 current->next= (stringgroup*) malloc(sizeof(stringgroup));
  112.                 if (current->next == NULL)
  113.                     {
  114.                     fprintf(erroroutput,"not enough mem for annotation group\n");
  115.                     break;
  116.                     }
  117.                 current = current->next;
  118.                 current->next = NULL;
  119.                 current->author = NULL;
  120.                 }
  121.             }
  122.         }
  123.     return(authorlist);
  124.     }
  125.  
  126.  
  127. void decode_annotations(FILE *mainfd,FILE *tablefd,textportions *portions)
  128.     {
  129.     int i;
  130.     U32 fcSttbfAtnbkmk,lcbSttbfAtnbkmk;
  131.     
  132.     U32 fcPlcfAtnbkf,lcbPlcfAtnbkf;
  133.     U32 fcPlcfAtnbkl,lcbPlcfAtnbkl;
  134.     
  135.  
  136.     fseek(mainfd,0x01C2,SEEK_SET);
  137.     fcSttbfAtnbkmk = read_32ubit(mainfd);
  138.     lcbSttbfAtnbkmk = read_32ubit(mainfd);
  139.     error(erroroutput,"table offset for annotations is %x %d\n",fcSttbfAtnbkmk,lcbSttbfAtnbkmk);
  140.  
  141.     extract_sttbf(&(portions->annotations),tablefd,fcSttbfAtnbkmk,lcbSttbfAtnbkmk);
  142.  
  143.     fseek(mainfd,0x01EA,SEEK_SET);
  144.  
  145.     fcPlcfAtnbkf=read_32ubit(mainfd);
  146.     lcbPlcfAtnbkf=read_32ubit(mainfd);
  147.     fcPlcfAtnbkl=read_32ubit(mainfd);
  148.     lcbPlcfAtnbkl=read_32ubit(mainfd);
  149.     error(erroroutput,"fcPlcfAtnbkf %x lcbPlcfAtnbkf %d\n",fcPlcfAtnbkf,lcbPlcfAtnbkf);
  150.     error(erroroutput,"fcPlcfAtnbkl %x lcbPlcfAtnbkl %d\n",fcPlcfAtnbkl,lcbPlcfAtnbkl);
  151.  
  152.     extract_bookm_limits(&( portions->a_bookmarks),tablefd,fcPlcfAtnbkf,lcbPlcfAtnbkf,fcPlcfAtnbkl,lcbPlcfAtnbkl);
  153.  
  154.     key_atrd=NULL;
  155.     if (portions->authors != NULL)
  156.         {
  157.         error(erroroutput,"no of strings here is %d\n",portions->authors->noofstrings);
  158.         key_atrd = (ATRD *) malloc(sizeof(ATRD) * portions->authors->noofstrings);
  159.         if (key_atrd == NULL)
  160.             {
  161.             fprintf(erroroutput,"mem alloc error\n");
  162.             return;
  163.             }
  164.         for (i=0;i<portions->annotations.no_of_strings;i++)
  165.             {
  166.             key_atrd->ibst = i;
  167.             key_atrd->xstUsrInitl[0] = 0;
  168.             }
  169.         }
  170.     }
  171.